package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p1 = new Person();
        System.out.println(p1);

        Person p2 = new Person();
        System.out.println(p2);

        //1.获取类对象
        Class cls = Class.forName("reflect.Person");
        /*
            java.lang.reflect.Constructor
            Constructor的每一个实例用来表示一个构造器,使用它可以相当于调用该构造器实例化对象
         */
        Constructor c = cls.getConstructor(String.class, int.class);
        Object obj = c.newInstance("王五", 33);
        System.out.println(obj);
    }
}
